package com.mimosa.common.system.department;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.mimosa.common.dao.HibernateDao;

/**
 * 部门信息DAO类
 */
@Repository
public class TDepartmentDao extends HibernateDao<TDepartment, String> {
	/**
	 * 获取当前部门的父部门的ID列表
	 * 
	 * @param departId
	 * @return
	 */
	public List<String> getParentDepartIds(String departId) {
		List<String> result = new LinkedList<String>();
		if (StringUtils.isNotBlank(departId)) {
			TDepartment depart = this.findUniqueBy("id", departId);
			if (depart != null && StringUtils.isNotBlank(depart.getParentId())) {
				while (depart != null && StringUtils.isNotBlank(depart.getParentId())) {
					depart = this.findUniqueBy("id", depart.getParentId());
					result.add(depart.getId());
				}
			}
		}

		return result;
	}
}